/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.socialNet.command;

import com.bionic.socialNet.commandBeans.UserBean;
import com.bionic.socialNet.entities.LoginData;
import com.bionic.socialNet.manager.Config;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Ann
 */
public class CommandRegister implements ICommand {

    private static final String EMAIL = "email";
    private static final String PASSWD = "password";

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = null;
        String login = request.getParameter(EMAIL);
        String pass = request.getParameter(PASSWD);

        UserBean user = new UserBean();
        LoginData registerData = new LoginData();
        registerData.setLogin(login);
        registerData.setPassword(pass);
        boolean isRegister = user.isRegisterNewUser(registerData);
        if (isRegister) {
            int userID = user.getCurrentUser().getUserID();
            request.setAttribute("userID", userID);
            page = Config.getInstance().getProperty(Config.PROFILE_EDIT);
        }

        return null;
    }
}
